package com.kaba.bean;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {

    //状态码
    private Integer code;
    //状态
    private String message;
    //返回封装数据
    private T data;

    public ResponseResult() {

    }

    public ResponseResult(Integer code) {
        this.code = code;
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    //不返回数据构造方法
    public ResponseResult(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    //返回数据构造方法
    public ResponseResult(ResultCode resultCode, T data) {
        this(resultCode);
        this.data = data;
    }






    //请求成功（不返回数据）
    public static <T> ResponseResult <T> success(){
        return new ResponseResult <T>(ResultCode.SUCCESS);
    }

    //请求成功（返回数据）
    public static <T> ResponseResult <T> success(T data){

        return new ResponseResult <T>(ResultCode.SUCCESS,data);
    }

    //操作异常的响应
    public static <T> ResponseResult <T> error(ResultCode resultCode){
        return new ResponseResult <T>(resultCode);
    }


    public static <T> ResponseResult <T> success(ResultCode resultCode, T data) {

        return new ResponseResult(resultCode, data);
    }
}


